<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>修改密码</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <!-- 页面  -->
	    <section class="AllContent">
	    	<div class="FormStyle ChangePassword" id="ChangePassword">
    			<ul>
    				<li>旧密码</li>
    				<li>
    					<input type="password" id="oldpwd"/>
    				</li>
    				<li>新密码</li>
    				<li>
    					<input type="password" id="newpwd"/>
    				</li>
    				<li>确认密码</li>
    				<li>
    					<input type="password" id="repwd"/>
    				</li>
    			</ul>
    			
    			<button class="NextButton" type="button" onclick="submitpwd();">确认修改</button>
    		</div>
    	</form>
	    </section>
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init();
		$('.AllHeader li:eq(1)').text('修改密码');
		
		$('#ChangePassword input').on('focus',function(){
			$(this).css({backgroundImage:'url(images/compile1.png)'});
			$(this).parents('li').css({borderBottom:'1px solid #10aef9'});
			$(this).parents('li').prev().css({borderBottom:'1px solid #10aef9'});
		})
		
		$('#ChangePassword input').on('blur',function(){
			$(this).parents('li').siblings().css({borderBottom:'1px solid #eee'});
			$(this).parents('li').css({borderBottom:'1px solid #eee'});
			$(this).css({backgroundImage:'url(images/compile.png)'});
		})
		
        function submitpwd() {
            var oldpwd = $("#oldpwd").val();
            var newpwd = $("#newpwd").val();
            var repwd = $("#repwd").val();
            if (empty(oldpwd)) {
                alertMessage("请输入旧的密码！");
                return;
            }
            if (empty(newpwd)) {
                alertMessage("请输入新的密码！");
                return;
            }
            if (newpwd !== repwd) {
                alertMessage("两次输入的密码不一致！");
                return;
            }
            $.ajax({//一个Ajax过程
                type: "post", //以post方式与后台沟通
                url: getServerUrl() + "/Open/ComSys/changepwd",
                dataType: 'json', //从php返回的值以 JSON方式 解释
                data: 'access_token=' + getToken()+'&oldpwd=' + oldpwd+'&pwd=' +newpwd,
                success: function (json) {//如果调用php成功
                    if (json.result == 1) {
                        window.localStorage.clear();
                        alertMessage("修改密码成功！");
                       
                        mui.openWindow({
						    url: 'login.html', 
						    id:'login.html'
						});
                    } else {
                        //hideLoading();
                        alertMessage("修改密码错误:[" + json.error_description + "]");

                    }
                }
            });
        }

        function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
        function onBackKeyDown() {
            openUrl("index.html");
        }

	</script>
</html>
